#include <queue>
#include <vector>

using namespace std;
class Node {
public:
  int val;
  vector<Node *> children;

  Node() {}

  Node(int _val) { val = _val; }

  Node(int _val, vector<Node *> _children) {
    val = _val;
    children = _children;
  }
};

vector<vector<int>> levelOrder(Node *root) {
  if (root == nullptr)
    return {};
  queue<Node *> q;
  q.push(root);
  vector<vector<int>> res;
  while (!q.empty()) {
    int n = q.size();
    vector<int> l;
    while (n--) {
      Node *node = q.front();
      q.pop();
      l.push_back(node->val);
      for (Node *child : node->children) {
        q.push(child);
      }
    }
    res.push_back(l);
  }
  return res;
}
